import {
  fatchJoke,
  fatchOneProblem,
  fatchSoul,
  fatchSweet,
  fatchComment,
  fatchAcg,
  fatchPoem,
  fatchCouplet,
  fetchEventHistory,
  fetchIdiom,
  getQr,
  getQQAvatar,
  getDouTu,
  uploadImg,
  get60S,
  getExpressInfo,
  searchDream,
  getWeather,
  searchMusic
} from './service';

const Model = {
  namespace: 'skill',
  state: {
    oneProblem: {},
    soul: {},
    sweet: {},
    comment: {},
    status: '',
    news: null
  },
  effects: {
    *fetch({ payload }, { put, call }) {
      yield put({
        type: 'saveOneProblem',
        payload: yield call(fatchOneProblem, payload),
      });
      yield put({
        type: 'saveSoul',
        payload: yield call(fatchSoul, payload),
      });
      yield put({
        type: 'saveSweet',
        payload: yield call(fatchSweet, payload),
      });
      yield put({
        type: 'saveComment',
        payload: yield call(fatchComment, payload),
      });
    },
    *fetchJoke({ payload }, { call }) {
      const response = yield call(fatchJoke, payload);
      return response;
    },
    *fatchOneProblem({ payload }, { call }) {
      return yield call(fatchOneProblem, payload);
    },
    *fatchSoul({ payload }, { call }) {
      return yield call(fatchSoul, payload);
    },
    *fatchSweet({ payload }, { call }) {
      return yield call(fatchSweet, payload);
    },
    *fatchComment({ payload }, { call }) {
      return yield call(fatchComment, payload);
    },
    *getACG({ payload }, { call }) {
      return yield call(fatchAcg, payload);
    },
    *fatchPoem({ payload }, { call }) {
      return yield call(fatchPoem, payload);
    },
    *fatchCouplet({ payload }, { call }) {
      return yield call(fatchCouplet, payload);
    },
    *fetchEventHistory({ payload }, { call }) {
      return yield call(fetchEventHistory, payload);
    },
    *fetchIdiom({ payload }, { call }) {
      return yield call(fetchIdiom, payload);
    },
    *getQr({ payload }, { call }) {
      return yield call(getQr, payload);
    },
    *getQQAvatar({ payload }, { call }) {
      return yield call(getQQAvatar, payload);
    },
    *getDouTu({ payload }, { call }) {
      return yield call(getDouTu, payload);
    },
    *uploadImg({ payload }, { call }) {
      return yield call(uploadImg, payload);
    },
    *get60S({ payload }, { put, call }) {
      yield put({
        type: 'saveNews',
        payload: yield call(get60S, payload),
      });
    },
    *getExpressInfo({ payload }, { call }) {
      return yield call(getExpressInfo, payload);
    },
    *searchDream({ payload }, { call }) {
      return yield call(searchDream, payload);
    },
    *getWeather({ payload }, { call }) {
      return yield call(getWeather, payload);
    },
    *searchMusic({ payload }, { call }) {
      return yield call(searchMusic, payload);
    }
  },
  reducers: {
    saveOneProblem(state, action) {
      return {
        ...state,
        oneProblem: action.payload.data,
        status: action.payload.code
      };
    },
    saveSoul(state, action) {
      return {
        ...state,
        soul: action.payload.data
      };
    },
    saveSweet(state, action) {
      return {
        ...state,
        sweet: action.payload.data
      };
    },
    saveComment(state, action) {
      return {
        ...state,
        comment: action.payload.data
      };
    },
    saveNews(state, action) {
      return {
        ...state,
        news: action.payload.data
      };
    },
  },
};
export default Model;
